<template>
  <el-card>
    <el-form inline="true" class="demo-form-inline">
      <el-form-item label="一级分类">
        <el-select
          :disabled="scene == 0 ? false : true"
          v-model="categoryStore.c1Id"
          @change="handler"
        >
          <!--option:label即为显示文字 value属性即为select下拉菜单收集的数据-->
          <el-option
            v-for="c1 of categoryStore.c1Arr"
            :key="c1.id"
            :label="c1.name"
            :value="c1.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="二级级分类">
        <el-select
          :disabled="scene == 0 ? false : true"
          v-model="categoryStore.c2Id"
          @change="handler2"
        >
          <el-option
            v-for="c2 of categoryStore.c2Arr"
            :key="c2.id"
            :label="c2.name"
            :value="c2.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="三级级分类">
        <el-select
          :disabled="scene == 0 ? false : true"
          v-model="categoryStore.c3Id"
        >
          <el-option
            v-for="c3 of categoryStore.c3Arr"
            :key="c3.id"
            :label="c3.name"
            :value="c3.id"
          />
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup lang="ts">
//引入生命周期的行数钩子
import { onMounted } from "vue"
import useCategoryStore from "../../store/modules/category.ts"

let categoryStore = useCategoryStore()

onMounted(() => {
  getC1()
})

const getC1 = () => {
  categoryStore.getC1()
}

const handler = () => {
  categoryStore.getC2()
  categoryStore.c2Id = ""
  categoryStore.c2Arr = []
  categoryStore.c3Id = ""
  categoryStore.c3Arr = []
}

const handler2 = () => {
  categoryStore.getC3()
  categoryStore.c3Id = ""
  categoryStore.c3Arr = []
}

//接受父组件传递的值
defineProps(["scene"])
</script>

<style scoped>
.demo-form-inline .el-input {
  --el-input-width: 220px;
}

.demo-form-inline .el-select {
  --el-select-width: 220px;
}
</style>
